package com.hxut.servlet;

import com.hxut.dao.GoodsDao;
import com.hxut.model.Goods;
import com.hxut.model.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "GoodsListPageServlet",urlPatterns = "/goodsListPageServlet")
public class GoodsListPageServlet extends HttpServlet {
    

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int currentPage = 1;
        if(req.getParameter("currentPage")!=null && !req.getParameter("currentPage").equals("")){
            currentPage = Integer.parseInt(req.getParameter("currentPage"));
        }

        int currentCount=8;
        if(req.getParameter("currentCount")!=null && !req.getParameter("currentCount").equals("")){
            currentCount = Integer.parseInt(req.getParameter("currentCount"));
        }

        GoodsDao goodsDao = new GoodsDao();
        PageBean pageBean = goodsDao.findGoodsByPage(currentPage, currentCount);
        //ArrayList<Goods> goodsList = pageBean.getGoodsList();
        req.setAttribute("pageBean",pageBean);
        req.getRequestDispatcher("/good-list.jsp").forward(req,resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
